home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 11 - 1995 / 11.11 Nov 95 / 11.11 Tips < prev    next >
Encoding:
Text File  |  1995-10-25  |  4.6 KB  |  118 lines  |  [TEXT/ttxt]

  1. Two Screen MacsBug
  2.  
  3. One feature of MacsBug that I like is the "swap" command, which lets you leave a second monitor display the debugger (and punches it out of the desktop).
  4. Then, if each DebugStr() ends in ";g"  you will get an onscreen log of the last 10 or 15 breaks. I used this to track an elusive bug that would freeze my Mac and trash Macsbug memory... I could see which breakpoint went last.
  5.  
  6. Matt Slot
  7.  
  8.  
  9.  
  10. Once Bitten Twice Shy
  11. HGetState does not return a valid handle state when you pass it an empty handle (one whose master pointer is NULL). Instead, it returns an error code, so before you call HGetState, be sure to check that the handle isn’t empty and execute an alternate code path if it is.
  12. I was bitten by this because I was using HGetState to determine if a handle was to a resource, and the resource had been purged, so HGetState returned an error code instead of the handle flags and I incorrectly thought the handle wasn’t to a resource.
  13. This is documented in Inside Macintosh, Memory, p. 1-61, but it bears some repeating.  Remeber to check the error values returned by toolbox calls.
  14. Eric Schlegel
  15.  
  16.  
  17. Informant in the Menu Bar
  18. I do drivers, and you just plain can’t set a breakpoint in ADB completion routines (freezes the keyboard so MacsBug is worthless!).
  19. So I throw one of the routines below into the routine to see when a piece of code gets executed.
  20. What does it do? It "lights up" a bar (length dependant on screen resolution) in the menu bar. So if you DotToggle(300); you get a flashing short line in the menu bar.
  21. [Leave this out of production code! Beware of using this on 24 bit color screens.  Make sure that the value of where will not cause anything to be written into the alpha channel.  Your best bet is to test with the screen that’s only 8 bits deep.  -sgs]
  22.  
  23. void DotOn(long where) {
  24.    long  *dot;
  25.    dot = (long *)(LMGetScrnBase() + where);
  26.    *dot |= -1;
  27. }
  28. void DotOff(long where) {
  29.    long  *dot;
  30.    dot = (long *)(LMGetScrnBase() + where);
  31.    *dot &= 0;
  32. }
  33. void DotToggle(long where) {
  34.    long  *dot;
  35.    dot = (long *)(LMGetScrnBase() + where);
  36.    *dot ^= -1;
  37. }
  38.  
  39. Dave Fleck
  40. Informative Cursors
  41. One technique that I have used in the past where dropping into the debugger wasn't an option, and logging wasn't getting flushed in time/took too long, was to create a bunch of cursors numbering 00 - 99, and made a call to set the cursor and return the number of the previous cursor:
  42.  
  43. routine1()
  44. {
  45. short oldCursor = setDebugCursor(15);
  46.     ...
  47.     (void) setDebugCursor(oldCursor);
  48. }
  49.  
  50. This way when the machine froze, the cursor would tell me what routine it had frozen in.
  51.  
  52. Tom Kimpton
  53.  
  54.  
  55. MPW Editor Primitives
  56. The MPW Command Reference describes 32 editor primitives which may be attached to any key sequence using the SetKey command.  While the SetKey command itself is useful, the list of editor primitives alone is useful to MPW script writers.
  57. Though only documented for use with SetKey, editor primitives may be used like any other MPW command: in scripts, command aliases, or AddMenu items.  There are a couple of advantages:
  58. 1) They only work on the active window and have sharply defined functions, you don’t have to remember any selection expressions or argument lists.  Compare:
  59.  
  60.          MoveStartOfFile
  61.     with
  62.            Find • "{Active}"
  63.  
  64. 2) They’re fast.  I haven’t put a stopwatch to it, but you can see the difference immediately in running a script that uses the primitives and one that doesn’t.
  65. The MPW Command reference lists these 32 primitives, the names of which should be self-explanatory:
  66.  
  67. DeleteCharLeft
  68. DeleteCharRight
  69. DeleteEndOfFile
  70. DeleteEndOfLine
  71. DeleteStartOfFile
  72. DeleteStartOfLine
  73. DeleteWordLeft
  74. DeleteWordRight
  75. MoveCharLeft
  76. MoveCharRight
  77. MoveEndOfLine
  78. MoveLineDown
  79. MoveLineUp
  80. MovePageDown
  81. MovePageUp
  82. MoveStartOfFile
  83. MoveStartOfLine
  84. MoveWordLeft
  85. MoveWordRight
  86. SelectCharLeft
  87. SelectCharRight
  88. SelectEndOfFile
  89. SelectEndOfLine
  90. SelectLineDown
  91. SelectLineUP
  92. SelectPageDown
  93. SelectPageUp
  94. SelectStartOfFile
  95. SelectStartOfLine
  96. SelectWordLeft
  97. SelectWordRight
  98.  
  99. There are also at least five primitives that aren’t in the command reference:
  100.  
  101. ScrollEnd
  102. ScrollHome
  103. ScrollPageDn
  104. ScrollPageUp
  105. DebuggerCommand
  106.  
  107. I can understand why Apple might not want users to casually drop into MacsBug from an MPW script, but I wonder why they chose not to document the scrolling commands?  Whatever the reason, you should obviously use caution when playing with undocumented features.
  108.  
  109.  
  110. Lee David Rimar
  111. Absoft Corporation
  112.  
  113. __________________________
  114. This is the text of an article orginially printed in MacTech Magazine™.  MacTech Magazine, for Macintosh Programmers and Developers.  For subscription information, please contact us at:
  115.   •  http://www.mactech.com
  116.   •  mailto:info@mactech.com
  117.   •  805/494-9797
  118.